package com.hq.modules.operate.controller;

import com.hq.common.annotation.SysLog;
import com.hq.common.utils.R;
import com.hq.modules.sys.controller.AbstractController;
import com.hq.modules.sys.dao.BuildingInfoMapper;
import com.hq.modules.sys.entity.BuildingInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 楼栋
 */
@RestController
@RequestMapping("/building")
public class BuildingController extends AbstractController {

    @Resource
    private BuildingInfoMapper buildingInfoMapper;


    /**
     * 新增楼栋信息
     */
    @SysLog("新增楼栋信息")
    @PostMapping("/saveBuildingInfo")
    public BuildingInfo saveBuildingInfo(@RequestBody BuildingInfo buildingInfo) {
        buildingInfoMapper.insertSelective(buildingInfo);
        buildingInfo.setId(buildingInfo.getId());
        return buildingInfo;
    }

    /**
     * 修改楼栋信息
     */
    @SysLog("修改楼栋信息")
    @PostMapping("/alertBuildingInfo")
    public R alertBuildingInfo(@RequestBody BuildingInfo buildingInfo) {
        buildingInfoMapper.updateByPrimaryKeySelective(buildingInfo);
        return R.ok();
    }

    /**
     * 移除楼栋信息
     */
    @SysLog("移除楼栋信息")
    @PostMapping("/removeBuildingInfo")
    public R removeBuildingInfo(@RequestBody BuildingInfo buildingInfo) {
        buildingInfoMapper.deleteByPrimaryKey(buildingInfo.getId());
        return R.ok();
    }

    /**
     * 查询某个小区楼栋信息
     */
    @SysLog("查询某个小区楼栋信息")
    @PostMapping("/selectAllBuildingInfo")
    public List<BuildingInfo> selectBuildingInfo(@RequestBody BuildingInfo buildingInfo) {
        List<BuildingInfo> buildingInfos = buildingInfoMapper.selectAllByRegionId(buildingInfo.getRegionId());
        return buildingInfos;
    }
    /**
     * 查询某个小区楼栋信息
     */
    @SysLog("查询某个小区楼栋信息")
    @PostMapping("/selectBuildingInfoById")
    public BuildingInfo selectBuildingInfoById(@RequestBody BuildingInfo buildingInfo) {
        BuildingInfo building = buildingInfoMapper.selectByPrimaryKey(buildingInfo.getId());
        return building;
    }
    /**
     * 全量查询某个小区楼栋信息
     */
    @SysLog("全量查询某个小区楼栋信息")
    @PostMapping("/getBuildingInfo")
    public List<BuildingInfo> getBuildingInfo(@RequestBody BuildingInfo buildingInfo) {
        List<BuildingInfo> buildingInfos = buildingInfoMapper.getBuildingInfo(buildingInfo);
        return buildingInfos;
    }
}
